﻿-- =============================================
-- Author:		Kevin Orbaker
-- Create date: 10/08/2007
-- Description:	Select alert history counts by application..
-- =============================================
CREATE PROCEDURE [dbo].[usp_select_AlertHistoryReportByServiceFault] 
	-- Add the parameters for the stored procedure here
	@ApplicationName varchar(256),
	@ServiceName varchar(256) =null,
	@BeginDate datetime,
	@EndDate datetime
AS
BEGIN
	DECLARE @DateRange int

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

SELECT     F.FaultID, F.NativeMessageID, F.ActivityID, F.[Application], F.[Description], F.ErrorType, F.FailureCategory, F.FaultCode, F.FaultDescription, F.FaultSeverity, F.Scope, 
                      F.ServiceInstanceID, F.ServiceName, F.FaultGenerator, F.MachineName, AH.[InsertedDate] as [DateTime], F.ExceptionMessage, F.ExceptionType, F.ExceptionSource, 
                      F.ExceptionTargetSite, F.ExceptionStackTrace, F.InnerExceptionMessage, F.InsertMessagesFlag, F.InsertedDate
FROM
dbo.AlertHistory AH,
	dbo.Fault F
	where AH.FaultID =F.FaultID
	AND AH.[Application] = @ApplicationName
	AND AH.[InsertedDate] between @BeginDate and @EndDate
    AND AH.ServiceName =@ServiceName 



END
